#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using i64 = long long;
void solve()
{
    int n;
    std::cin >> n;
    std::vector<i64> a(n);
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i];
    }

    i64 ans = std::accumulate(a.begin(), a.end(), 0ll);
    for (int i = 0; i + 1 < n; ++i)
    {
        if (a[0] < a.back())
        {
            std::reverse(a.begin(), a.end());
        }

        i64 sum = 0;
        for (int i = 0; i + 1 < a.size(); ++i)
        {
            a[i] = a[i] - a[i + 1];
            sum += a[i];
        }

        ans = std::max(ans, sum);
        a.pop_back();
    }
    std::cout << ans << "\n";
}

int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
